interface TimeRange {
  dates: [string, string];
  timeRange: [string, string];
  price: number;
  name: string;
  enable: boolean;
}

function hasOverlappingTimeRanges(ranges: TimeRange[]): boolean {
  // 检查每对时间段
  for (let i = 0; i < ranges.length; i++) {
    for (let j = i + 1; j < ranges.length; j++) {
      const a = ranges[i];
      const b = ranges[j];
      
      // 1. 先检查日期是否有重叠
      const aStartDate = new Date(a.dates[0]);
      const aEndDate = new Date(a.dates[1]);
      const bStartDate = new Date(b.dates[0]);
      const bEndDate = new Date(b.dates[1]);
      
      if (aStartDate <= bEndDate && bStartDate <= aEndDate) {
        // 2. 日期有重叠的情况下，检查时间段是否交叉
        const aStartTime = a.timeRange[0].split(':').map(Number);
        const aEndTime = a.timeRange[1].split(':').map(Number);
        const bStartTime = b.timeRange[0].split(':').map(Number);
        const bEndTime = b.timeRange[1].split(':').map(Number);
        
        // 转换为分钟数便于比较
        const aStart = aStartTime[0] * 60 + aStartTime[1];
        const aEnd = aEndTime[0] * 60 + aEndTime[1];
        const bStart = bStartTime[0] * 60 + bStartTime[1];
        const bEnd = bEndTime[0] * 60 + bEndTime[1];
        
        // 检查时间段是否重叠
        if (aStart < bEnd && bStart < aEnd) {
          return true;
        }
      }
    }
  }
  
  return false;
}